﻿using EMall.IdentityService.IdentityServers;
using IdentityServer4.EntityFramework.Entities;
using Microsoft.EntityFrameworkCore;

namespace EMall.IdentityService.Users
{
    public class IdentityServerRepository : IIdentityServerRepository
    {
        private readonly IdentityServiceDbContext _dbContext;
        public IdentityServerRepository(IdentityServiceDbContext dbContext)
        {
            _dbContext = dbContext;
        }
        public async Task AddClientAsync(Client client)
        {
            await _dbContext.Clients.AddAsync(client);
        }
        public async Task RemoveClientAsync(Client client)
        {
            _dbContext.Clients.Remove(client);
            await Task.CompletedTask;
        }
        public async Task RemoveClientScopeAsync(ClientScope clientScope)
        {
            _dbContext.ClientScopes.Remove(clientScope);
            await Task.CompletedTask;
        }
        public async Task AddIdentityResourceAsync(IdentityResource identityResource)
        {
            await _dbContext.IdentityResources.AddAsync(identityResource);
        }
        public async Task RemoveIdentityResourceAsync(IdentityResource identityResource)
        {
            _dbContext.IdentityResources.Remove(identityResource);
            await Task.CompletedTask;
        }
        public async Task AddApiResourceAsync(ApiResource apiResource)
        {
            await _dbContext.ApiResources.AddAsync(apiResource);
        }
        public async Task RemoveApiResourceAsync(ApiResource apiResource)
        {
            _dbContext.ApiResources.Remove(apiResource);
            await Task.CompletedTask;
        }
        public async Task AddApiScopeAsync(ApiScope apiScope)
        {
            await _dbContext.ApiScopes.AddAsync(apiScope);
        }
        public async Task RemoveApiScopeAsync(ApiScope apiScope)
        {
            _dbContext.ApiScopes.Remove(apiScope);
            await Task.CompletedTask;
        }

    }
}
